﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Himp.TaskScheduling.Migrations
{
    /// <inheritdoc />
    public partial class init : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.EnsureSchema(
                name: "TaskScheduling");

            migrationBuilder.CreateTable(
                name: "TS_BizflowConfig",
                schema: "TaskScheduling",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    BizflowName = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    BizflowCode = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    WorkflowModelKey = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    WorkflowModelName = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    WorkflowTypeProvider = table.Column<int>(type: "int", nullable: false),
                    ProviderKey = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ValiFlag = table.Column<bool>(type: "bit", nullable: false),
                    TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_TS_BizflowConfig", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "TS_ParamConfig",
                schema: "TaskScheduling",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    ParamType = table.Column<int>(type: "int", nullable: false),
                    ParamCodg = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    ParamName = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    PropertyID = table.Column<int>(type: "int", nullable: true),
                    PropertyType = table.Column<int>(type: "int", nullable: true),
                    ParamValue = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    DefValue = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    KeyPath = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ValiFlag = table.Column<bool>(type: "bit", nullable: false),
                    ParentId = table.Column<long>(type: "bigint", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_TS_ParamConfig", x => x.Id);
                    table.ForeignKey(
                        name: "FK_TS_ParamConfig_TS_ParamConfig_ParentId",
                        column: x => x.ParentId,
                        principalSchema: "TaskScheduling",
                        principalTable: "TS_ParamConfig",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateTable(
                name: "TS_ParamConfigTask",
                schema: "TaskScheduling",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    ParamCodg = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    TaskType = table.Column<int>(type: "int", nullable: false),
                    ParamValue = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    OperatorName = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    TaskStas = table.Column<int>(type: "int", nullable: false),
                    TaskMsg = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    OperationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    ExecTime = table.Column<DateTime>(type: "datetime2", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_TS_ParamConfigTask", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "TS_SampleObtainTask",
                schema: "TaskScheduling",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    TaskType = table.Column<int>(type: "int", nullable: false),
                    CoalTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    TaskState = table.Column<int>(type: "int", nullable: false),
                    TaskEndFlag = table.Column<bool>(type: "bit", nullable: false),
                    TaskStartTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    TaskEndTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CustCode = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    SampleCode = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    SamplePreparationCode = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    AssayCode = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    ExtractCode = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    SeparateCode = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    CoalType = table.Column<int>(type: "int", nullable: false),
                    Opercode = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    Opername = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    TestItemCode = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    task_remark = table.Column<string>(type: "nvarchar(max)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_TS_SampleObtainTask", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "TS_BizflowNode",
                schema: "TaskScheduling",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    BizflowConfigId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    WorkflowNodeKey = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    WorkflowNodeName = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    WorkflowNodeType = table.Column<int>(type: "int", nullable: false),
                    WorkflowIndex = table.Column<int>(type: "int", nullable: false),
                    SchemaUI = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    AssigneeParName = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    CaudidateUsersParName = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    CaudidateGroupsParName = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    AssigneeDefValues = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    CandidateUsersDefValues = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    CandidateGroupsDefValues = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    Component = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ValiFlag = table.Column<bool>(type: "bit", nullable: false),
                    CanAuditFlag = table.Column<bool>(type: "bit", nullable: false),
                    CanRejectFlag = table.Column<bool>(type: "bit", nullable: false),
                    CanEditFlag = table.Column<bool>(type: "bit", nullable: false),
                    TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_TS_BizflowNode", x => x.Id);
                    table.ForeignKey(
                        name: "FK_TS_BizflowNode_TS_BizflowConfig_BizflowConfigId",
                        column: x => x.BizflowConfigId,
                        principalSchema: "TaskScheduling",
                        principalTable: "TS_BizflowConfig",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "TS_BizflowNodeAssocCandidateUser",
                schema: "TaskScheduling",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    BizflowNodeId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    UserCode = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    UserName = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_TS_BizflowNodeAssocCandidateUser", x => x.Id);
                    table.ForeignKey(
                        name: "FK_TS_BizflowNodeAssocCandidateUser_TS_BizflowNode_BizflowNodeId",
                        column: x => x.BizflowNodeId,
                        principalSchema: "TaskScheduling",
                        principalTable: "TS_BizflowNode",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_TS_BizflowNode_BizflowConfigId",
                schema: "TaskScheduling",
                table: "TS_BizflowNode",
                column: "BizflowConfigId");

            migrationBuilder.CreateIndex(
                name: "IX_TS_BizflowNodeAssocCandidateUser_BizflowNodeId",
                schema: "TaskScheduling",
                table: "TS_BizflowNodeAssocCandidateUser",
                column: "BizflowNodeId");

            migrationBuilder.CreateIndex(
                name: "IX_TS_ParamConfig_ParentId",
                schema: "TaskScheduling",
                table: "TS_ParamConfig",
                column: "ParentId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "TS_BizflowNodeAssocCandidateUser",
                schema: "TaskScheduling");

            migrationBuilder.DropTable(
                name: "TS_ParamConfig",
                schema: "TaskScheduling");

            migrationBuilder.DropTable(
                name: "TS_ParamConfigTask",
                schema: "TaskScheduling");

            migrationBuilder.DropTable(
                name: "TS_SampleObtainTask",
                schema: "TaskScheduling");

            migrationBuilder.DropTable(
                name: "TS_BizflowNode",
                schema: "TaskScheduling");

            migrationBuilder.DropTable(
                name: "TS_BizflowConfig",
                schema: "TaskScheduling");
        }
    }
}
